package com.bt.controller.admin;

import com.bt.dto.SysMenuDTO;
import com.bt.entity.SysMenu;
import com.bt.result.Result;
import com.bt.service.SysMenuService;
import com.bt.vo.SysMenuVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @Description
 * @Author XJL
 * @Date 2023-04-30 14:32
 */
@Api(tags = "菜单管理相关接口")
@RestController
@Slf4j
@RequestMapping("/sys_menu")
public class SysMenuController {

    @Autowired
    private SysMenuService sysMenuService;

    /**
     * 修改菜单
     *
     * @param sysMenu
     * @return
     */
    @PostMapping("/update")
    @ApiOperation("修改菜单")
    public Result update(@RequestBody SysMenu sysMenu) {
        sysMenuService.update(sysMenu);

        return Result.success(sysMenu);
    }

    /**
     * 查询所有菜单
     *
     * @return
     */
    @GetMapping("/allData")
    @ApiOperation("查询所有菜单")
    public Result<List<SysMenuVO>> allData() {
        List<SysMenuVO> sysMenuVOList = sysMenuService.allData();

        return Result.success(sysMenuVOList);
    }


    /**
     * 菜单添加接口
     *
     * @param sysMenuDTO
     * @return
     */
    @ApiOperation(" 菜单添加接口")
    @PostMapping("/add")
    public Result add(@RequestBody SysMenuDTO sysMenuDTO) {
        log.info("菜单添加接口:{}", sysMenuDTO);
        sysMenuService.add(sysMenuDTO);
        return Result.success();
    }

    /**
     * 根据id查询菜单(数据回显)
     *
     * @param id
     * @return
     */
    @ApiOperation(" 根据id查询菜单(数据回显)")
    @GetMapping("/rowInfo")
    public Result<SysMenu> rowInfo(Integer id) {
        SysMenu sysMenu = sysMenuService.rowInfo(id);
        return Result.success(sysMenu);
    }


    /**
     * 菜单删除接口
     * @param id
     * @return
     */
    @ApiOperation("菜单删除接口")
    @GetMapping("/del")
    public Result del(Integer id){
        log.info("菜单删除接口:{}",id);
        sysMenuService.del(id);
        return Result.success();
    }
}
